package com.aigou.admin.aigouspringboot.service.impl;

import com.aigou.admin.aigouspringboot.common.Constants;
import com.aigou.admin.aigouspringboot.entity.OrderProduct;
import com.aigou.admin.aigouspringboot.entity.Product;
import com.aigou.admin.aigouspringboot.mapper.OrderProductMapper;
import com.aigou.admin.aigouspringboot.service.OrderProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class OrderProductServiceImpl implements OrderProductService {

    @Resource
    private OrderProductMapper orderProductMapper;

    @Override
    public List<OrderProduct> selectAll() {
        return orderProductMapper.selectAll();
    }

    @Override
    public PageInfo<OrderProduct> selectOrderProductListByPage(Integer current) {
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        // 查询所有用户信息
        List<OrderProduct> orderproductList = orderProductMapper.selectAll();
        // 把userList放入返回分页信息
        return new PageInfo<>(orderproductList);
    }

    @Override
    public int deleteById(String id) {
         return orderProductMapper.deleteByPrimaryKey(id);
    }

    @Override
    public OrderProduct selectById(String id) {
        return orderProductMapper.selectByPrimaryKey(id);
    }

    @Override
    public int edit(OrderProduct orderproduct) {
        return orderProductMapper.updateByPrimaryKeySelective(orderproduct);
    }

    @Override
    public int save(OrderProduct orderproduct) {
        return orderProductMapper.insertSelective(orderproduct);
    }

    @Override
    public List<Product> getProduct(String userId) {
        return orderProductMapper.getProductByUserId(userId);
    }

    @Override
    public OrderProduct selctNum(String userId) {
//        return orderProductMapper.getProductByUserId(userId);
        return null;
    }

    @Override
    public int deleteOrderById(String id) {
        orderProductMapper.deleteByPrimaryKey(id);
        return orderProductMapper.deleteOrderById(id);
    }
}
